# -*- coding: utf-8 -*-

import orjson
from datetime import datetime
from fastapi.encoders import jsonable_encoder
from .common import *


# alter table sys_user add hashed_password nvarchar(255) COLLATE Chinese_PRC_CI_AS NULL
@add_serializer
class User(YgBase):
    __tablename__: str = "sys_user"
    __table_args__ = {'extend_existing': True}

    id: Mapped[str] = mapped_column(primary_key=True)
    username: Mapped[required_unique_name]
    hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
    avatar: Mapped[Optional[str]] = mapped_column(String(255))
    birthday: Mapped[datetime.date]
    sex: Mapped[Optional[bool]]
    email: Mapped[Optional[str]] = mapped_column(String(45))
    phone: Mapped[Optional[str]] = mapped_column(String(45))
    org_code: Mapped[Optional[str]] = mapped_column(String(64))
    status: Mapped[bool]
    activiti_sync: Mapped[bool]
    work_no: Mapped[Optional[str]] = mapped_column(String(100))
    post: Mapped[Optional[str]] = mapped_column(String(100))
    telephone: Mapped[Optional[str]] = mapped_column(String(45))

    def __repr__(self) -> str:
        return f'id: {self.id}, name: {self.username}'

    def __str__(self) -> str:
        return f'id: {self.id}, name: {self.username}'




